import {
	createStore
} from 'vuex'
import {
	getNotice
} from "@/common/api.js"
const store = createStore({
	state: { //存放状态
		noticeList: [],
		sceneCode: -1,
	},
	mutations: {
		setNoticeList(state, payload) {
			state.noticeList = payload;
		},
		setSceneCode(state, payload) {
			state.sceneCode = payload;
		}
	},
	getters: {
		getNotice: state => {
			if (state.noticeList.length > 1) {
				return state.noticeList;
			} else {
				return state.noticeList[0]
			}

		}
	},
	actions: {
		noticeAction(context) {
			getNotice().then(res => {
				if (!res.data) {
					context.commit('setNoticeList', [])
				} else {
					context.commit('setNoticeList', res.data)
				}
			}).catch(error => {
				console.log("出错了")
			})
		}
	}
})

export default store